package com.sghd.pojo.fight.game;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frank
 * @date 2018-10-25 10:20
 * @desc 玩家基本信息
 **/
public class PlayerVo extends Sn {
    /**************************************************/
    private long playerId;
    private String name;
    private int headIcon;
    /** 玩家战斗技能及等级 */
    private Map<Integer, Integer> skills;
    /** 玩家五行等级 */
    private Map<ChessType, Integer> elements;
    /** 玩家当前关卡*/
    private LevelVo levelVo;
    /**************************************************/
    @JsonIgnore
    private int index;
    @JsonIgnore
    private boolean ready;
    private long money;
    /** 匹配次数*/
    @JsonIgnore
    private int matchTimes;
    @JsonIgnore
    private UnitEnum type;

    /**************************************************/
    public static PlayerVo valueOf(long sn, long playerId, String name, int headIcon) {
        PlayerVo vo = new PlayerVo();
        vo.sn = sn;
        vo.playerId = playerId;
        vo.name = name;
        vo.headIcon = headIcon;
        vo.skills = new HashMap<>(16);
        vo.elements = new HashMap<>(16);
        for (ChessType chessType : ChessType.values()) {
            if (chessType == ChessType.CT_LIGHTNING) {
                continue;
            }
            vo.elements.put(chessType, 0);
        }
        return vo;
    }

    public static PlayerVo valueOfRoobot(long playerId, String name, int headIcon) {
        PlayerVo playerVo = valueOf(playerId, name, headIcon);
        playerVo.type = UnitEnum.ROBOT;
        return playerVo;
    }

    @JsonIgnore
    public boolean canMatch(LevelVo level) {
        if (levelVo == null || level.getLevelStr().compareTo(levelVo.getLevelStr()) > 0) {
            return false;
        }

        return true;
    }

    public void match() {
        matchTimes++;
    }

    public int getMatchTimes() {
        return matchTimes;
    }

    public void setMatchTimes(int matchTimes) {
        this.matchTimes = matchTimes;
    }

    public UnitEnum getType() {
        return type;
    }

    public void setType(UnitEnum type) {
        this.type = type;
    }

    public static PlayerVo valueOf(long playerId, String name, int headIcon) {
        return valueOf(0, playerId, name, headIcon);
    }

    public long getPlayerId() {
        return playerId;
    }

    public void setPlayerId(long playerId) {
        this.playerId = playerId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public LevelVo getLevelVo() {
        return levelVo;
    }

    public void setLevelVo(LevelVo levelVo) {
        this.levelVo = levelVo;
    }

    public Map<Integer, Integer> getSkills() {
        return skills;
    }

    public void setSkills(Map<Integer, Integer> skills) {
        this.skills = skills;
    }

    public Map<ChessType, Integer> getElements() {
        return elements;
    }

    public void setElements(Map<ChessType, Integer> elements) {
        this.elements = elements;
    }

    public boolean isReady() {
        return ready;
    }

    public void setReady(boolean ready) {
        this.ready = ready;
    }

    public int getHeadIcon() {
        return headIcon;
    }

    public void setHeadIcon(int headIcon) {
        this.headIcon = headIcon;
    }

    public long getMoney() {
        return money;
    }

    public void setMoney(long money) {
        this.money = money;
    }

    @JsonIgnore
    public boolean isRoobot() {
        return type == UnitEnum.ROBOT;
    }
}
